package design2.proxy.example.downloader;

import design2.proxy.example.some_cool_media_library.ThirdPartyYouTubeLib;
import design2.proxy.example.some_cool_media_library.Video;

import java.util.HashMap;

/**
 * 媒体下载应用
 */
public class YouTubeDownloader {

	private ThirdPartyYouTubeLib api;

	public YouTubeDownloader(ThirdPartyYouTubeLib api) {
		this.api = api;
	}

	//提供
	public void renderVideoPage(String videoId) {
		Video video = api.getVideo(videoId);
		System.out.println("\n-------------------------------");
		System.out.println("视频页面（想象一下华丽的HTML）");
		System.out.println("ID: " + video.id);
		System.out.println("Title: " + video.title);
		System.out.println("Video: " + video.data);
		System.out.println("-------------------------------\n");
	}

	//渲染器
	public void renderPopularVideos() {
		HashMap<String, Video> list = api.popularVideos();
		System.out.println("\n-------------------------------");
		System.out.println("YouTube上最流行的视频（想象一下花哨的HTML）");
		for (Video video : list.values()) {
			System.out.println("ID: " + video.id + " / Title: " + video.title);
		}
		System.out.println("-------------------------------\n");
	}
}
